
#ifndef __TAPIERRORCODES_H__
#define __TAPIERRORCODES_H__


#ifdef __TELEPHONY_TYPE
#define __ERRORCODE_TYPE                            ErrorT
#else
#define __ERRORCODE_TYPE                            _ELASTOS ECode
#endif /* __TELEPHONY_TYPE */


#define __MAKE_ATC_ECODE(info, code) \
    ((__ERRORCODE_TYPE) ( \
    ((__ERRORCODE_TYPE) (1) << 31) | \
    ((__ERRORCODE_TYPE) (0x41) << 24) | \
    ((__ERRORCODE_TYPE) (info) << 16) | \
    ((__ERRORCODE_TYPE) (code))))

// get telephony error class
#define __GET_ERRORCLASS(errorno) ((__ERRORCODE_TYPE) (((errorno) >> 16) & 0xFF))

// -----------------------------------------------------------------------------
// General Errors Class
#define __INFO_GEN                                  0x00

// -----------------------------------------------------------------------------
// CME Errors Class
#define __INFO_CME                                  0x01

// SMS Errors Class
#define __INFO_CMS                                  0x02

// User-defined Errors Class
#define __INFO_CUS                                  0x03

// General Errors
#ifdef __TELEPHONY_TYPE
#define E_GEN_OK                                    ((__ERRORCODE_TYPE)0)
#define E_GEN_PARAM                                 ((__ERRORCODE_TYPE)0x81260000)
#define E_GEN_OUTOFMEM                              ((__ERRORCODE_TYPE)0x81250000)
#define E_GEN_UNIMPL                                ((__ERRORCODE_TYPE)0x80010000)
#define E_GEN_BUFTOOSMALL                           ((__ERRORCODE_TYPE)0x81200000)
#define E_GEN_NOTSUPPORTED                          ((__ERRORCODE_TYPE)0x811E0000)
#define E_GEN_INVALIDOPERATION                      ((__ERRORCODE_TYPE)0x810F0000)
#else
#define E_GEN_OK                                    NOERROR
#define E_GEN_PARAM                                 E_INVALID_ARGUMENT
#define E_GEN_OUTOFMEM                              E_OUT_OF_MEMORY
#define E_GEN_UNIMPL                                E_NOT_IMPLEMENTED
#define E_GEN_BUFTOOSMALL                           E_BUFFER_TOO_SMALL
#define E_GEN_NOTSUPPORTED                          E_NOT_SUPPORTED
#define E_GEN_INVALIDOPERATION                      E_INVALID_OPERATION
#endif /* __TELEPHONY_TYPE */

#define E_GEN_NOCARRIER                 __MAKE_ATC_ECODE(__INFO_GEN, 1  ) // Link is not established, or link disconnected
#define E_GEN_GENERALERROR              __MAKE_ATC_ECODE(__INFO_GEN, 2  ) // Invalid command, or command line too long
#define E_GEN_BUSY                      __MAKE_ATC_ECODE(__INFO_GEN, 3  ) // Busy signal detected
#define E_GEN_NOANSWER                  __MAKE_ATC_ECODE(__INFO_GEN, 4  ) // Connection completion timeouts
#define E_GEN_TIMEOUT                   __MAKE_ATC_ECODE(__INFO_GEN, 5  ) // device timeout
#define E_GEN_RESINITFAILED             __MAKE_ATC_ECODE(__INFO_GEN, 6  ) // initialize failed
#define E_GEN_SENDLINE                  __MAKE_ATC_ECODE(__INFO_GEN, 7  ) // Communication send line error
#define E_GEN_RECEIVELINE               __MAKE_ATC_ECODE(__INFO_GEN, 8  ) // Communication receive line error
#define E_GEN_INTERNAL                  __MAKE_ATC_ECODE(__INFO_GEN, 9  ) // internal error
#define E_GEN_NOTREADY                  __MAKE_ATC_ECODE(__INFO_GEN, 10 ) // not ready
#define E_GEN_FAIL                      __MAKE_ATC_ECODE(__INFO_GEN, 11 ) // function process failed
#define E_GEN_ABORT                     __MAKE_ATC_ECODE(__INFO_GEN, 12 ) // abort
#define E_GEN_NOTINITIALIZE             __MAKE_ATC_ECODE(__INFO_GEN, 13 ) // not initialize
#define E_GEN_RESTRICTIVE               __MAKE_ATC_ECODE(__INFO_GEN, 14 ) // restrictive
#define E_GEN_PARSEFAILED               __MAKE_ATC_ECODE(__INFO_GEN, 15 ) // parse failed
#define E_GEN_NOTFOUND                  __MAKE_ATC_ECODE(__INFO_GEN, 16 ) // not found
#define E_GEN_CMDTOOLONG                __MAKE_ATC_ECODE(__INFO_GEN, 17 ) // command too long
#define E_GEN_OUTOFRANGE                __MAKE_ATC_ECODE(__INFO_GEN, 18 ) // out of range
#define E_GEN_VOIDCONTENT               __MAKE_ATC_ECODE(__INFO_GEN, 19 ) // the content of the object is void

// CME ERRORS related to GSM, excluding SMS (GSM 07.07)
#define E_CME_PHONEFAILURE              __MAKE_ATC_ECODE(__INFO_CME, 0  ) // 0 @constdefine Phone failure
#define E_CME_NOCONNECTION              __MAKE_ATC_ECODE(__INFO_CME, 1  ) // 1 No connection to phone
#define E_CME_ADAPTERLINKRESERVED       __MAKE_ATC_ECODE(__INFO_CME, 2  ) // 2 Phone-adapter link reserved
#define E_CME_OPERATIONNOTALLOWED       __MAKE_ATC_ECODE(__INFO_CME, 3  ) // 3 Operation not allowed
#define E_CME_OPERATIONNOTSUPPORTED     __MAKE_ATC_ECODE(__INFO_CME, 4  ) // 4 Operation not supported
#define E_CME_PHSIMPINREQUIRED          __MAKE_ATC_ECODE(__INFO_CME, 5  ) // 5 PH-SIM PIN required
#define E_CME_PHFSIMPINREQUIRED         __MAKE_ATC_ECODE(__INFO_CME, 6  ) // 6 PH-FSIM PIN required
#define E_CME_PHFSIMPUKREQUIRED         __MAKE_ATC_ECODE(__INFO_CME, 7  ) // 7 PH-FSIM PUK required
#define E_CME_SIMNOTINSERTED            __MAKE_ATC_ECODE(__INFO_CME, 10 ) // 10 SIM not inserted
#define E_CME_SIMPINREQUIRED            __MAKE_ATC_ECODE(__INFO_CME, 11 ) // 11 SIM PIN required
#define E_CME_SIMPUKREQUIRED            __MAKE_ATC_ECODE(__INFO_CME, 12 ) // 12 SIM PUK required
#define E_CME_SIMFAILURE                __MAKE_ATC_ECODE(__INFO_CME, 13 ) // 13 SIM failure
#define E_CME_SIMBUSY                   __MAKE_ATC_ECODE(__INFO_CME, 14 ) // 14 SIM busy
#define E_CME_SIMWRONG                  __MAKE_ATC_ECODE(__INFO_CME, 15 ) // 15 SIM wrong
#define E_CME_INCORRECTPASSWORD         __MAKE_ATC_ECODE(__INFO_CME, 16 ) // 16 Incorrect password
#define E_CME_SIMPIN2REQUIRED           __MAKE_ATC_ECODE(__INFO_CME, 17 ) // 17 SIM PIN2 required
#define E_CME_SIMPUK2REQUIRED           __MAKE_ATC_ECODE(__INFO_CME, 18 ) // 18 SIM PUK2 required
#define E_CME_MEMORYFULL                __MAKE_ATC_ECODE(__INFO_CME, 20 ) // 20 Memory full
#define E_CME_INVALIDINDEX              __MAKE_ATC_ECODE(__INFO_CME, 21 ) // 21 Invalid index
#define E_CME_NOTFOUND                  __MAKE_ATC_ECODE(__INFO_CME, 22 ) // 22 A requested storage entry was not found
#define E_CME_MEMORYFAILURE             __MAKE_ATC_ECODE(__INFO_CME, 23 ) // 23 Storage memory failure
#define E_CME_TOOLONGTEXTSTRING         __MAKE_ATC_ECODE(__INFO_CME, 24 ) // 24 Text string too long
#define E_CME_INVALIDTEXTCHARACTERS     __MAKE_ATC_ECODE(__INFO_CME, 25 ) // 25 Invalid characters in text string
#define E_CME_TOOLONGADDRESS            __MAKE_ATC_ECODE(__INFO_CME, 26 ) // 26 Dial string too long
#define E_CME_INVALIDDIALCHARACTERS     __MAKE_ATC_ECODE(__INFO_CME, 27 ) // 27 Invalid characters in dial string
#define E_CME_NONETWORKSERVICE          __MAKE_ATC_ECODE(__INFO_CME, 30 ) // 30 No network service
#define E_CME_NETWORKTIMEOUT            __MAKE_ATC_ECODE(__INFO_CME, 31 ) // 31 Network timeout
#define E_CME_NETWORKACCESS             __MAKE_ATC_ECODE(__INFO_CME, 32 ) // 32 Network not allowed - emergency calls only
#define E_CME_NETWKPINREQUIRED          __MAKE_ATC_ECODE(__INFO_CME, 40 ) // 40 Network personalization PIN required
#define E_CME_NETWKPUKREQUIRED          __MAKE_ATC_ECODE(__INFO_CME, 41 ) // 41 Network personalization PUK required
#define E_CME_SUBSETPINREQUIRED         __MAKE_ATC_ECODE(__INFO_CME, 42 ) // 42 Network subset personalization PIN required
#define E_CME_SUBSETPUKREQUIRED         __MAKE_ATC_ECODE(__INFO_CME, 43 ) // 43 Network subset personalization PUK required
#define E_CME_SVCPINREQUIRED            __MAKE_ATC_ECODE(__INFO_CME, 44 ) // 44 Service Provider Personalization PIN is required to perform this operation
#define E_CME_SVCPUKREQUIRED            __MAKE_ATC_ECODE(__INFO_CME, 45 ) // 45 Service provider personalization PUK required
#define E_CME_CORPPINREQUIRED           __MAKE_ATC_ECODE(__INFO_CME, 46 ) // 46 Corporate personalization PIN required
#define E_CME_CORPPUKREQUIRED           __MAKE_ATC_ECODE(__INFO_CME, 47 ) // 47 Corporate personalization PUK required
#define E_CME_UNDETERMINED              __MAKE_ATC_ECODE(__INFO_CME, 100) // 100 Unknown
#define E_CME_OPERTEMPNOTALLOWED        __MAKE_ATC_ECODE(__INFO_CME, 256) /* 256 Operation temporarily not allowed */
#define E_CME_CALLBARRED                __MAKE_ATC_ECODE(__INFO_CME, 257) /* 257 call barred */
#define E_CME_PHONEISBUSY               __MAKE_ATC_ECODE(__INFO_CME, 258) /* 258 phone is busy */
#define E_CME_USERABORT                 __MAKE_ATC_ECODE(__INFO_CME, 259) /* 259 user abort */
#define E_CME_INVALIDDIALSTRING         __MAKE_ATC_ECODE(__INFO_CME, 260) /* 260 invalid dial string */
#define E_CME_SSNOTEXECUTED             __MAKE_ATC_ECODE(__INFO_CME, 261) /* 261 ss not executed */
#define E_CME_SIMBLOCKED                __MAKE_ATC_ECODE(__INFO_CME, 262) /* 262 SIM blocked */

// CMS ERRORS related to SMS (GSM 07.05)

#define E_CMS_UNASSIGNEDNUMBER          __MAKE_ATC_ECODE(__INFO_CMS, 1  ) // 1  Unassigned (unallocated) number
#define E_CMS_OPERDETERMINEDBARRING     __MAKE_ATC_ECODE(__INFO_CMS, 8  ) // 8  Operator determined barring
#define E_CMS_CALLBARRED                __MAKE_ATC_ECODE(__INFO_CMS, 10 ) // 10 Call barred
#define E_CMS_MSGBARREDBYOPERATOR       __MAKE_ATC_ECODE(__INFO_CMS, 21 ) // 21 Short message transfer rejected
#define E_CMS_DESTINATIONOUTOFSVC       __MAKE_ATC_ECODE(__INFO_CMS, 27 ) // 27 Destination out of service
#define E_CMS_UNIDENTIFIEDSUBCRIBER     __MAKE_ATC_ECODE(__INFO_CMS, 28 ) // 28 Unidentified subscriber
#define E_CMS_FACILITYREJECTED          __MAKE_ATC_ECODE(__INFO_CMS, 29 ) // 29 Facility rejected
#define E_CMS_UNKNOWNSUBCRIBER          __MAKE_ATC_ECODE(__INFO_CMS, 30 ) // 30 Unknown subscriber
#define E_CMS_NETWORKUNSUPPORTED        __MAKE_ATC_ECODE(__INFO_CMS, 38 ) // 38 Network out of order
#define E_CMS_TEMPORARYFAILURE          __MAKE_ATC_ECODE(__INFO_CMS, 41 ) // 41 Temporary failure
#define E_CMS_CONGESTION                __MAKE_ATC_ECODE(__INFO_CMS, 42 ) // 42 Congestion
#define E_CMS_RESUNAVAILABLE            __MAKE_ATC_ECODE(__INFO_CMS, 47 ) // 47 Resources unavailable, unspecified
#define E_CMS_SVCNOTSUBSCRIBED          __MAKE_ATC_ECODE(__INFO_CMS, 50 ) // 50 Requested facility not subscribed
#define E_CMS_SVCNOTIMPLEMENTED         __MAKE_ATC_ECODE(__INFO_CMS, 69 ) // 69 Requested facility not implemented
#define E_CMS_INVALIDMR                 __MAKE_ATC_ECODE(__INFO_CMS, 81 ) // 81 Invalid short message transfer reference value
#define E_CMS_INVALIDMSG                __MAKE_ATC_ECODE(__INFO_CMS, 95 ) // 95 Invalid message, unspecified
#define E_CMS_INVALIDMANDATORYINFO      __MAKE_ATC_ECODE(__INFO_CMS, 96 ) // 96 Invalid mandatory information
#define E_CMS_MSGTYPENOTIMPLEMENTED     __MAKE_ATC_ECODE(__INFO_CMS, 97 ) // 97 Message type non-existent or not implemented
#define E_CMS_MSGNOTCOMPATIBLE          __MAKE_ATC_ECODE(__INFO_CMS, 98 ) // 98 Message not compatible with short message protocol state
#define E_CMS_INFOELEMENTNOTIMPLEMENTED __MAKE_ATC_ECODE(__INFO_CMS, 99 ) // 99 Information element non-existent or not implemented
#define E_CMS_INVALIDPROTOCOL           __MAKE_ATC_ECODE(__INFO_CMS, 111) // 111 Protocol error, unspecified
#define E_CMS_INTERWORKING              __MAKE_ATC_ECODE(__INFO_CMS, 127) // 127 Interworking, unspecified
#define E_CMS_TELEMATIC                 __MAKE_ATC_ECODE(__INFO_CMS, 128) // 128 Telematic interworking not supported
#define E_CMS_MSGTYPENOTSUPPORTED       __MAKE_ATC_ECODE(__INFO_CMS, 129) // 129 Short message Type 0 not supported
#define E_CMS_MSGNOTREPLACE             __MAKE_ATC_ECODE(__INFO_CMS, 130) // 130 Cannot replace short message
#define E_CMS_UNSPECIFIEDTPPID          __MAKE_ATC_ECODE(__INFO_CMS, 143) // 143 Unspecified TP-PID error
#define E_CMS_DCSNOTSUPPORTED           __MAKE_ATC_ECODE(__INFO_CMS, 144) // 144 Data coding scheme (alphabet) not supported
#define E_CMS_MSGCLSNOTSUPPORTED        __MAKE_ATC_ECODE(__INFO_CMS, 145) // 145 Message class not supported
#define E_CMS_DCSUNSPECIFIED            __MAKE_ATC_ECODE(__INFO_CMS, 159) // 159 Unspecified TP-DCS error
#define E_CMS_COMMANDEXECUTEERROR       __MAKE_ATC_ECODE(__INFO_CMS, 160) // 160 Command cannot be carried out
#define E_CMS_COMMANDUNSUPPORTED        __MAKE_ATC_ECODE(__INFO_CMS, 161) // 161 Command unsupported
#define E_CMS_UNSPECIFIEDTPCOMMAND      __MAKE_ATC_ECODE(__INFO_CMS, 175) // 175 Unspecified TP-Command error
#define E_CMS_TPDUNOTSUPPORTED          __MAKE_ATC_ECODE(__INFO_CMS, 176) // 176 TPDU not supported
#define E_CMS_SCBUSY                    __MAKE_ATC_ECODE(__INFO_CMS, 192) // 192 SC busy
#define E_CMS_NOSCSUBSCRIPTION          __MAKE_ATC_ECODE(__INFO_CMS, 193) // 193 No SC subscription
#define E_CMS_SMSC                      __MAKE_ATC_ECODE(__INFO_CMS, 194) // 194 SC system failure
#define E_CMS_INVALIDSMEADDRESS         __MAKE_ATC_ECODE(__INFO_CMS, 195) // 195 Invalid SME address
#define E_CMS_MSGCALLBARRED             __MAKE_ATC_ECODE(__INFO_CMS, 196) // 196 Destination SME barred
#define E_CMS_REJECTEDDUPLICATESM       __MAKE_ATC_ECODE(__INFO_CMS, 197) // 197 SM rejected-duplicate SM
#define E_CMS_TPVPFNOTSUPPORTED         __MAKE_ATC_ECODE(__INFO_CMS, 198) // 198 TP-VPF not supported
#define E_CMS_TPVPNOTSUPPORTED          __MAKE_ATC_ECODE(__INFO_CMS, 199) // 199 TP-VP not supported
#define E_CMS_SIMSMSSTORAGEFULL         __MAKE_ATC_ECODE(__INFO_CMS, 208) // 208 D0 SIM SMS storage full
#define E_CMS_NOSIMMSGSTORAGE           __MAKE_ATC_ECODE(__INFO_CMS, 209) // 209 No SMS storage capability in SIM
#define E_CMS_MSERROR                   __MAKE_ATC_ECODE(__INFO_CMS, 210) // 210 Error in MS
#define E_CMS_MEMORYCAPACITYEXCEEDED    __MAKE_ATC_ECODE(__INFO_CMS, 211) // 211 Memory capacity exceeded
#define E_CMS_SIMTOOLKITBUSY            __MAKE_ATC_ECODE(__INFO_CMS, 212) // 212 SIM Application Toolkit busy
#define E_CMS_SIMDOWNLOADERROR          __MAKE_ATC_ECODE(__INFO_CMS, 213) // 213 SIM data download error
#define E_CMS_UNSPECIFIEDERRORCAUSE     __MAKE_ATC_ECODE(__INFO_CMS, 255) // 255 Unspecified error cause
#define E_CMS_MEFAILURE                 __MAKE_ATC_ECODE(__INFO_CMS, 300) // 300 ME failure
#define E_CMS_MESMSSVCRESERVED          __MAKE_ATC_ECODE(__INFO_CMS, 301) // 301 SMS service of ME reserved
#define E_CMS_OPERATIONNOTALLOWED       __MAKE_ATC_ECODE(__INFO_CMS, 302) // 302 Operation not allowed
#define E_CMS_OPERATIONNOTSUPPORTED     __MAKE_ATC_ECODE(__INFO_CMS, 303) // 303 Operation not supported
#define E_CMS_INVALIDPDUMODEPARAMETER   __MAKE_ATC_ECODE(__INFO_CMS, 304) // 304 Invalid PDU mode parameter
#define E_CMS_INVALIDTEXTMODEPARAMETER  __MAKE_ATC_ECODE(__INFO_CMS, 305) // 305 Invalid text mode parameter
#define E_CMS_SIMNOTINSERTED            __MAKE_ATC_ECODE(__INFO_CMS, 310) // 310 SIM not inserted
#define E_CMS_SIMPINREQUIRED            __MAKE_ATC_ECODE(__INFO_CMS, 311) // 311 SIM PIN required
#define E_CMS_PHSIMPINREQUIRED          __MAKE_ATC_ECODE(__INFO_CMS, 312) // 312 PH-SIM PIN required
#define E_CMS_SIMFAILURE                __MAKE_ATC_ECODE(__INFO_CMS, 313) // 313 SIM failure
#define E_CMS_SIMBUSY                   __MAKE_ATC_ECODE(__INFO_CMS, 314) // 314 SIM busy
#define E_CMS_SIMWRONG                  __MAKE_ATC_ECODE(__INFO_CMS, 315) // 315 SIM wrong
#define E_CMS_SIMPUKREQUIRED            __MAKE_ATC_ECODE(__INFO_CMS, 316) // 316 SIM PUK required
#define E_CMS_SIMPIN2REQUIRED           __MAKE_ATC_ECODE(__INFO_CMS, 317) // 317 SIM PIN2 required
#define E_CMS_SIMPUK2REQUIRED           __MAKE_ATC_ECODE(__INFO_CMS, 318) // 318 SIM PUK2 required
#define E_CMS_MEMORYFAILURE             __MAKE_ATC_ECODE(__INFO_CMS, 320) // 320 Memory failure
#define E_CMS_INVALIDINDEX              __MAKE_ATC_ECODE(__INFO_CMS, 321) // 321 Invalid memory index
#define E_CMS_MEMORYFULL                __MAKE_ATC_ECODE(__INFO_CMS, 322) // 322 Memory full
#define E_CMS_SMSCADDRESSUNKNOWN        __MAKE_ATC_ECODE(__INFO_CMS, 330) // 330 SMSC address unknown
#define E_CMS_NONETWORK                 __MAKE_ATC_ECODE(__INFO_CMS, 331) // 331 no network service
#define E_CMS_NETWORKTIMEOUT            __MAKE_ATC_ECODE(__INFO_CMS, 332) // 332 Network timeout
#define E_CMS_NOCNMAACKNOWLEDGEEXPECTED __MAKE_ATC_ECODE(__INFO_CMS, 340) // 340 No +CNMA acknowledge expected
#define E_CMS_UNKNOWNERROR              __MAKE_ATC_ECODE(__INFO_CMS, 500) // 500 Unknown error
#define E_CMS_USERABORT                 __MAKE_ATC_ECODE(__INFO_CMS, 512) // 512 User abort

// User-defined Errors Class
#define E_CUS_FDNONLY                   __MAKE_ATC_ECODE(__INFO_CUS, 1)   // dial FDN only

#endif  /* __TAPIERRORCODES_H__ */

